package nongchang.kuaijiecaifu.com.ncapp_android.util.countdown;

import android.os.CountDownTimer;
import android.widget.TextView;

import ezy.lite.util.DateTime;

public class RevealCountDown extends CountDownTimer {
    final TextView txt;
    final Runnable onFinish;

    public RevealCountDown(TextView tv, long time, Runnable runnable) {
        super(time, 10);
        cancel(tv);
        this.onFinish = runnable;
        this.txt = tv;
        this.txt.setTag(this);
    }

    @Override
    public void onTick(long s) {
        String time = DateTime.format("mm:ss:SSS", s);
        txt.setText(time.substring(0, time.length() - 1));
    }

    @Override
    public void onFinish() {
        txt.setText("开奖中...");
        onFinish.run();
    }

    public static void cancel(TextView tv) {
        CountDownTimer timer = (CountDownTimer) tv.getTag();
        if (timer != null) {
            timer.cancel();
        }
        tv.setText("开奖中...");
        tv.setTag(null);
    }

}